<template>
  <basic-container>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
      <!-- <template slot="menuRight">
        <el-button
          type="warning"
          size="small"
          plain
          icon="el-icon-download"
          @click="handleExport"
          >导出
        </el-button>
      </template> -->
      <template slot-scope="{}" slot="tenantIdSearch">
        <select-page
          ref="searchSerSelect"
          label="tenantName"
          value="tenantId"
          :select.sync="search.tenantId"
          :url="'blade-system/tenant/list'"
          placeholder-text="OEM"
          filter-key="tenantName"
        ></select-page>
      </template>
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page
          ref="searchSerSelect"
          label="serviceName"
          value="serviceNo"
          :select.sync="search.serviceNo"
          :url="'rb-core/core/serviceinfo/service_info/list'"
          placeholder-text="服务商"
          filter-key="serviceName"
        ></select-page>
      </template>
      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page
          ref="searchSerSelect"
          label="rpiName"
          value="rpiNo"
          :select.sync="search.rpiNo"
          :url="'rb-core/core/merchant/merchant_info/list'"
          placeholder-text="商户"
          filter-key="rpiName"
        ></select-page>
      </template>
      <template slot-scope="{}" slot="aisleCodeSearch">
        <select-page
          ref="searchSerSelect"
          label="aisleName"
          value="aisleCode"
          :select.sync="search.aisleCode"
          :url="'rb-core/core/aisle/pay_aisle/list'"
          placeholder-text="通道"
          filter-key="aisleName"
        ></select-page>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { getList, getExport } from "@/api/rb-core/posinfo/merchantChannel";
import { mapGetters } from "vuex";
import selectPage from "@/components/select-page/select-page";

export default {
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: true,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        selection: true,
        searchMenuSpan: 24,
        columnBtn: false,
        labelWidth: 200, //弹出表单的标题的统一宽度
        searchLabelWidth: 150, //搜索框标题宽度
        menuWidth: 100, //操作栏宽度
        emptyBtnText: "重置",
        align: "center",
        // searchIcon:true,
        // searchIndex:3,
        column: [
          {
            label: "OEM品牌商编号",
            searchLabel: "OEM品牌商",
            searchOrder: 1,
            prop: "tenantId",
            type: "select",
            display: false,
            search: true,
            rules: [
              {
                required: true,
                message: "请选择OEM品牌商",
                trigger: "blur",
              },
            ],
            overHidden: true,
            width: 150,
          },
          {
            label: "OEM品牌商名称",
            prop: "tenantName",
            display: false,
            rules: [
              {
                required: true,
                message: "请选择OEM品牌商",
                trigger: "blur",
              },
            ],
            overHidden: true,
            width: 150,
          },
          {
            label: "服务商编号",
            prop: "serviceNo",
            type: "select",
            display: false,
            search: true,
            searchLabel: "服务商",
            searchOrder: 2,
            rules: [
              {
                required: true,
                message: "请选择服务商",
                trigger: "blur",
              },
            ],
            overHidden: true,
            width: 150,
          },
          {
            label: "服务商名称",
            prop: "serviceName",
            type: "input",
            width: 200,
          },
          {
            label: "",
            prop: "isSelectChild",
            type: "select",
            multiple: false,
            dataType: "string",
            showColumn: false,
            search: true,
            searchType: "checkbox",
            searchSpan: 0,
            searchLabelWidth: "0",
            searchOrder: 3,
            dicData: [
              {
                label: "包含下级",
                value: 1,
              },
            ],
            hide: true,
            display: false,
          },
          {
            label: "商户类型",
            prop: "merchantType",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=merchant_type",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            showColumn: false,
            hide: true,
            search: true,
            searchOrder: 9,
            rules: [
              {
                required: true,
                message: "请输入接入类型",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "商户类型",
            prop: "merchantTypeName",
            span: 24,
            type: "input",
            rules: [
              {
                required: true,
                message: "请输入接入类型",
                trigger: "blur",
              },
            ],
          },
          {
            label: "商户编号",
            prop: "rpiNo",
            type: "select",
            display: false,
            search: true,
            searchLabel: "商户名称",
            searchOrder: 3,
            rules: [
              {
                required: true,
                message: "请输入商户号",
                trigger: "blur",
              },
            ],
            overHidden: true,
            width: 140,
          },
          {
            label: "通道商户编号",
            search: true,
            prop: "aisleRpiNo",
            type: "input",
            overHidden: true,
            minWidth: 100,
            searchOrder: 3,
          },
          // {
          //   label: "商户名称",
          //   prop: "rpiName",
          //   type: "input",
          //   search: true,
          //   width: 200,
          //   searchOrder: 5
          // },
          {
            label: "注册名称",
            prop: "registeredName",
            type: "input",
            search: true,
            searchOrder: 6,
            width: 200,
          },
          {
            label: "商户简称",
            prop: "userShortName",
            type: "input",
            search: true,
            width: 200,
            searchOrder: 7,
          },
          {
            label: "通道编号",
            searchLabel: '通道名称',
            prop: "aisleCode",
            type: "input",
            search: true,
            searchOrder: 10,
            rules: [
              {
                required: true,
                message: "请输入通道编号",
                trigger: "blur",
              },
            ],
          },
          {
            label: "通道名称",
            prop: "aisleName",
            type: "input",
            minWidth: 92,
            overHidden: true,
          },
          {
            label: "微信子商户号",
            prop: "wxWechatId",
            type: "input",
            minWidth: 110,
            overHidden: true,
          },
          {
            label: "支付宝子商户号",
            prop: "aliAlipayId",
            type: "input",
            minWidth: 110,
            overHidden: true,
          },
          {
            label: "微信费率",
            prop: "wxRate",
            type: "input",
            children: [
              {
                label: "扫码支付",
                prop: "wxRate",
                width: 120,
                display: false,
              },
              {
                label: "付款码支付",
                prop: "wxRate",
                width: 100,
                type: "input",
              },
              {
                label: "公众号支付",
                prop: "wxRate",
                width: 100,
                type: "input",
              },
              {
                label: "小程序支付",
                prop: "wxRate",
                width: 100,
                type: "input",
              },
              {
                label: "APP支付",
                prop: "wxRate",
                width: 100,
                type: "input",
              },
            ],
            overHidden: true,
          },
          {
            label: "支付宝费率",
            prop: "zfbRate",
            type: "input",
            children: [
              {
                label: "扫码支付",
                prop: "zfbRate",
                width: 120,
                display: false,
              },
              {
                label: "付款码支付",
                prop: "zfbRate",
                width: 100,
                type: "input",
              },
              {
                label: "公众号支付",
                prop: "zfbRate",
                width: 100,
                type: "input",
              },
              {
                label: "小程序支付",
                prop: "zfbRate",
                width: 100,
                type: "input",
              },
              {
                label: "APP支付",
                prop: "zfbRate",
                width: 100,
                type: "input",
              },
            ],
            overHidden: true,
            minWidth: 92,
          },
          {
            label: "银联云闪付小额",
            prop: "unionRate",
            type: "input",
            children: [
              {
                label: "扫码支付",
                prop: "unionRate",
                width: 120,
                display: false,
              },
              {
                label: "付款码支付",
                prop: "unionRate",
                width: 100,
                type: "input",
              },
              {
                label: "公众号支付",
                prop: "unionRate",
                width: 100,
                type: "input",
              },
              {
                label: "小程序支付",
                prop: "unionRate",
                width: 100,
                type: "input",
              },
              {
                label: "APP支付",
                prop: "unionRate",
                width: 100,
                type: "input",
              },
            ],
            overHidden: true,
            minWidth: 92,
          },
          {
            label: "银联云闪付大额",
            prop: "unionRate",
            type: "input",
            children: [
              {
                label: "借记卡",
                prop: "unionDebitRate",
                width: 120,
                display: false,
              },
              {
                label: "借记卡封顶",
                prop: "unionDebitMax",
                width: 100,
                type: "input",
              },
              {
                label: "贷记卡",
                prop: "unionCreditRate",
                width: 100,
                type: "input",
              }
            ],
            overHidden: true,
            minWidth: 92,
          },
          {
            label: "刷卡",
            prop: "unionRate",
            type: "input",
            children: [
              {
                label: "借记卡",
                prop: "debitRate",
                width: 120,
                display: false,
              },
              {
                label: "借记卡封顶",
                prop: "debitMax",
                width: 100,
                type: "input",
              },
              {
                label: "贷记卡",
                prop: "creditRate",
                width: 100,
                type: "input",
              }
            ],
            overHidden: true,
            minWidth: 92,
          },
          {
            label: "秒到费",
            prop: "unionRate",
            type: "input",
            children: [
              {
                label: "扫码",
                prop: "codeAdvanceRate",
                width: 120,
                display: false,
              },
              {
                label: "刷卡借记卡",
                prop: "debitCodeAdvanceRate",
                width: 100,
                type: "input",
              },
              {
                label: "刷卡贷记卡",
                prop: "creditCodeAdvanceRate",
                width: 100,
                type: "input",
              }
            ],
            overHidden: true,
            minWidth: 92,
          },
          {
            label: "创建时间",
            prop: "createTime",
            type: "input",
            overHidden: true,
            minWidth: 140,
          },
          {
            label: "创建日期",
            prop: "timeData",
            type: "datetimerange",
            searchRange: true,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "创建日期开始时间",
            endPlaceholder: "创建日期结束时间",
            search: true,
            rules: [
              {
                required: true,
                message: "请选择创建日期",
                trigger: "blur",
              },
            ],
            hide: true,
            display: false,
            searchSpan: 12,
          },
          // {
          //   label: "通道名称",
          //   prop: "aisleKind",
          //   type: "select",
          //   props: {
          //     label: "dictValue",
          //     value: "dictKey",
          //   },
          //   dataType: "number",
          //   dicUrl: "/api/blade-system/dict/dictionary?code=aisle_kind",
          //   search: true,
          //   overHidden: true,
          //   showColumn: false,
          //   minWidth: 80,
          //   searchOrder: 19,
          //   display: false,
          //   hide: true,
          // },
        ],
      },
      data: [],
      countData: {},
    };
  },
  components: {
    selectPage
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        viewBtn: this.vaildData(
          this.permission.service_merhcant_rate_view,
          false
        ),
        exportBtn: this.vaildData(
          this.permission.service_merhcant_rate_export,
          false
        ),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    exhibition() {
      return (val) => {
        if (val == "" || val == "-1") {
          return (val = 0);
        } else {
          return val;
        }
      };
    },
  },
  watch: {
    "search.timeData"(val) {
      if (val) {
        this.search.beginTime = val[0];
        this.search.endTime = val[1];
      } else {
        this.search.beginTime = "";
        this.search.endTime = "";
      }
    },
  },
  methods: {
    // 获取 代理商
    // getServiceInfoSimpleList(param) {
    //   serviceInfoSimpleList(param).then((res) => {
    //     // this.rptNoList = res.data.data.records;
    //     const column = this.findObject(this.option.column, "serviceNo");
    //     column.dicData = res.data.data;
    //   })
    // },
    /**
     * @func 详情
     * @desc 点击详情进入详情界面
     * @param {Object} row - 商户信息
     * */
    handleDetail(row) {
      this.$router.push({
        name: "交易详情",
        query: {
          rptAisleOrderCode: row.rptAisleOrderCode,
        },
      });
    },
    /**
     * @func edit,view 打开之前回调
     * @desc 点击获取点击天数时间
     * */
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    /**
     * @func 重置
     * @desc 重置查询条件
     * */
    searchReset() {
      this.query = {};
      this.search = {};
      this.$set(this.search, "timeData", ["", ""]);
      this.onLoad(this.page);
    },
    /**
     * @func 搜索
     * @desc 根据条件查询
     * @param {params} params --- 条件查询
     * */
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    /**
     * @func 选中单元格
     * @desc 选中单元格数据
     * @param {list} list --- 选中单元格数据-数组
     * */
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * @func 分页页码
     * @desc 分页页码改变时会触发
     * */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      // this.refreshChange();
    },
    /**
     * @func 当前页个数
     * @desc pageSize改变时会触发
     * */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      // this.refreshChange();
    },
    /**
     * @func 刷新
     * @desc 点击刷新按钮触发该事件
     * */
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 初始化
     * @desc 表格初始化查询数据
     * */
    onLoad(page, params = {}) {
      this.loading = true;
      // if(this.query.isSelectChildArr){
      //   this.query.isSelectChild = this.query.isSelectChildArr[0];
      // }
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    /**
     * @func 导出
     * @desc 根据条件导出
     * */
    handleExport() {
      let params = {
        ...this.search,
        current: "-1",
        size: "-1",
      };

      this.$confirm("是否导出用户数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        getExport(params).then(
          (res) => {
            this.$message({
              type: "success",
              message: res.data.msg,
            });
          },
          (error) => {
            window.console.log(error);
          }
        );
      });
    },
    /**
     * @func 排序
     * @desc 根据表格字段排序
     * */
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>

<style lang="scss" scoped>
.curd-foter {
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
}

.redFontBox {
  margin-right: 40px;
  .redFont {
    color: red;
  }
}
/deep/ .el-tag--dark.el-tag--success {
  border: none !important;
}
</style>